package utils

import (
	"cloud-disk/core/define"
	"context"
	"github.com/minio/minio-go/v7"
	"net/http"
	"path"
)

func MinioUpload(r *http.Request, client *minio.Client) (string, error) {
	file, fileHeader, err := r.FormFile("file")
	bucketName := "cloud-disk"
	objectName := GetUUID() + path.Ext(fileHeader.Filename)
	_, err = client.PutObject(context.Background(), bucketName, objectName, file, fileHeader.Size, minio.PutObjectOptions{ContentType: "binary/octet-stream"})
	if err != nil {
		return "", err
	}
	return define.Endpoint + "/" + bucketName + "/" + objectName, nil
}
